<?php
/*! \brief
 * This is the Simple Factory Class that generate widget framework db relative object
 * \author William Su
 */
class WFDbFactory
{
    private static $instance;
    /**
     * @var WF
     */
    private $objFramework;
    public function __construct($objFramework){
        $this->objFramework = $objFramework;
    }
    /**
     * @return WFSqlGenSqlite
     */
    public function getSqlGen(){
        if(! isset(self::$instance[__FUNCTION__])){
            require dirname(__FILE__) . '/../../config.php';
            $strDbConfigType = $this->objFramework->getConfigFactory()->getConfig()->getDbConfigType();
            $strSuffixClassName = 'SqlGen' . $this->objFramework->getTypeFactory()->getString()->getUpperCamelCase($strDbConfigType);
            require_once $strSuffixClassName . '.php';
            $strClassName = 'WF' . $strSuffixClassName;
            self::$instance[__FUNCTION__] = new $strClassName($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     * @return WFDB
     */
    public function getDB(){
        if(! isset(self::$instance[__FUNCTION__])){
            require_once dirname(__FILE__) . '/DB.php';
            self::$instance[__FUNCTION__] = new WFDB($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    /**
     * @return WFFixtures
     */
    public function getFixtures(){
        if(! isset(self::$instance[__FUNCTION__])){
            require_once dirname(__FILE__) . '/fixtures/Fixtures.php';
            self::$instance[__FUNCTION__] = new WFFixtures($this->objFramework);
        }
        return self::$instance[__FUNCTION__];
    }
    public function destroyInstance(){
        unset(self::$instance);
    }
}